﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

public static class DeviceInfo  {

    public static string GetSystemInfo()
    {
        //string systemInfo =
        //    "设备模型：" + SystemInfo.deviceModel +
        //    "\n设备名称：" + SystemInfo.deviceName +
        //    "\n设备类型：" + SystemInfo.deviceType +
        //    "\n设备唯一标识符：" + SystemInfo.deviceUniqueIdentifier +
        //    "\n显卡标识符：" + SystemInfo.graphicsDeviceID +
        //    "\n显卡设备名称：" + SystemInfo.graphicsDeviceName +
        //    "\n显卡厂商：" + SystemInfo.graphicsDeviceVendor +
        //    "\n显卡厂商ID:" + SystemInfo.graphicsDeviceVendorID +
        //    "\n显卡支持版本:" + SystemInfo.graphicsDeviceVersion +
        //    "\n显存（M）：" + SystemInfo.graphicsMemorySize +
        //    "\n显卡支持Shader层级：" + SystemInfo.graphicsShaderLevel +
        //    "\n支持最大图片尺寸：" + SystemInfo.maxTextureSize +
        //    "\nnpotSupport：" + SystemInfo.npotSupport +
        //    "\n操作系统：" + SystemInfo.operatingSystem +
        //    "\nCPU处理核数：" + SystemInfo.processorCount +
        //    "\nCPU类型：" + SystemInfo.processorType +
        //    "\n内存大小：" + SystemInfo.systemMemorySize +
        //    "\nsupportedRenderTargetCount：" + SystemInfo.supportedRenderTargetCount +
        //    "\nsupports3DTextures：" + SystemInfo.supports3DTextures +
        //    "\nsupportsAccelerometer：" + SystemInfo.supportsAccelerometer +
        //    "\nsupportsComputeShaders：" + SystemInfo.supportsComputeShaders +
        //    "\nsupportsGyroscope：" + SystemInfo.supportsGyroscope +
        //    "\nsupportsImageEffects：" + SystemInfo.supportsImageEffects +
        //    "\nsupportsInstancing：" + SystemInfo.supportsInstancing +
        //    "\nsupportsLocationService：" + SystemInfo.supportsLocationService +
        //    "\nsupportsRenderToCubemap：" + SystemInfo.supportsRenderToCubemap +
        //    "\n是否支持内置阴影：" + SystemInfo.supportsShadows +
        //    "\nsupportsSparseTextures：" + SystemInfo.supportsSparseTextures +
        //    "\nsupportsVibration：" + SystemInfo.supportsVibration +
        //    "\n系统语言：" + Application.systemLanguage +
        //    "\n沙盒地址：" + Application.persistentDataPath;

        //return systemInfo;

        Dictionary<string, string> valueDic = new Dictionary<string, string>();

        GetClassPropertyInfo<SystemInfo>(valueDic);
        GetClassPropertyInfo<Screen>(valueDic);
        GetClassPropertyInfo<Application>(valueDic);

        string info = "";
        foreach (var item in valueDic)
        {
            info += item.Key + " : " + item.Value + "\n";
        }

        return info;
    }

    private static void GetClassPropertyInfo<T>(Dictionary<string,string> valueDic)
    {
        Type type = typeof(T);
        PropertyInfo[] fs = type.GetProperties(BindingFlags.Static | BindingFlags.Public);
        foreach (var f in fs)
        {
            object value = f.GetValue(null);
            string name = type.Name +"."+ f.Name;
            string v_str = value == null ? "Null" : value.ToString();
            valueDic.Add(name, v_str);
        }
    }
}
